Skip to content

feat(desktop): send a highlighted code selection to an agent with file context - #5334

Draft
jgreer013 wants to merge 8 commits into
ParadevAI:mainfrom
jgreer013:jgreer013/code-inspection-context
Draft

jgreer013 wants to merge 8 commits into
ParadevAI:mainfrom
jgreer013:jgreer013/code-inspection-context

Conversation

@jgreer013

@jgreer013 jgreer013 commented Jun 23, 2026 •

Copy link
Copy Markdown

Summary

Highlight code in the desktop file viewer or a git diff and send it — with its file path and line range — straight to an agent, no copy-paste.

  • File viewer: highlight → "Send selection to agent" button or ⌘/Ctrl+↵. Goes to the active agent (new session if none open; toast if no agent configured).
  • Git diff: select via the gutter or just highlight the code text → composer opens → ⌘/Ctrl+↵ sends (message optional).

Both share one formatter/send path, so the agent gets the same context shape either way.

Type of Change

  • New feature

Testing

  • bun run lint
  • bun run typecheck
  • bun test (unit tests for capture/bound/format/dispatch + the diff line-resolver, which is also verified against the live @pierre/diffs shadow DOM)
  • Manual: open a file or diff in a v2 workspace, highlight, send — with an agent open and with none open

Notes

Deferred (follow-up)

  • In-app chat dispatch — this PR sends a selection to the terminal agent (Claude Code). Sending it into the in-app chat pane instead is designed but not built (path: launchAgentSession({kind:"chat"})); a follow-up.

…e context

Wire selection capture in the v2 code viewer into the existing agent prompt
pipeline: highlight a region and send it — with its file path and line range —
to the active/open agent (or a new session if none is open).

Adds getSelection() on the v2 CodeEditorAdapter, a useSendSelectionToAgent hook
(bounded snippets, supersede guard, toast-on-error keep-for-retry), and the
FilePane/ViewProps wiring that mounts a "Send selection to agent" affordance in
CodeView. Reuses formatAgentPromptWithFileContext as the shared formatter seam.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a7b0adf-cffc-4634-a2e3-e2d96e6c5b49

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ghost

ghost commented Jun 23, 2026 •

Copy link
Copy Markdown

…ncile edge ParadevAI#4, debounce selection handler

- Extract the edge-ParadevAI#5 supersede guard into a pure isStillCurrent(token,
  currentToken) and unit-test both branches (renderHook unavailable in this
  test harness). Hook now calls it instead of an inline ref compare.
- Make edge ParadevAI#4 refuse-only explicit: extract shouldRefuseSelection() (null/
  empty + defensive empty-path / non-finite-line guard) and unit-test it;
  the v2 CodeView host always has a resolvable ViewProps.filePath, so the
  text-only fallback is unreachable in PR1 and deferred to PR2.
- Debounce CodeEditor's onSelectionChange so selection-derived UI recomputes
  on selection settle (120ms) instead of every CodeMirror selectionSet,
  mirroring the DiffPane sibling's onLineSelectionEnd cadence.
…t is available

CHANGE 1 (no-agent feedback): when a valid selection has no resolvable
target (no live terminal agent AND no agent config — resolver yields
null), send() now surfaces a clear, actionable sonner toast ('No agent
available to send to. Start an agent in this workspace, or add one in
Settings -> Agents.') instead of the misleading 'couldn't start a new
session' error. The decision is a pure classifier resolveSendOutcome()
mapping (region, target) -> 'dispatch' | 'no-agent' | 'no-selection',
unit-tested without a renderHook harness.

CHANGE 2 (Mod-Enter shortcut): bind Cmd/Ctrl+Enter in the v2 CodeEditor
keymap (alongside Mod-s) to trigger the same default-target send as the
button. onSendSelection is threaded CodeView -> CodeEditor and held in a
ref (mirrors onSelectionChangeRef). The keymap entry reuses the adapter's
captureSelection as the selection-presence gate: consumes the chord
(returns true) only when a non-empty selection exists, else returns false
so Mod-Enter falls through to default editor behavior (no stray newline).
The button stays; the shortcut is an addition.
Relax the AgentCommentComposer submit gate so a comment is no longer
required — ⌘/Ctrl+↵ now sends just the selected line reference. The shared
prompt formatter emits the bare anchor (no dangling ': ') when the comment
is empty.
…d host

pr-review: the per-host pointerup registry keyed dedup on the DOM node but
captured itemId once, so a host node reused for a different file could
dispatch to a stale itemId; and the settle-timer could fire after the host
detached. Hold itemId in a mutable per-host entry (refreshed on re-render)
and bail the settle callback when the host is no longer connected.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant